/* Main file for nRF24 module implementation
 * This will implement the entire RF
 * comunication protocol
 * */

#include "a_nRF24L01.h"
#include "serial_com.h"
#include "timers_control.h"
#include "mirf.h"

#define D_SERIAL

volatile unsigned long now;

int main(void)
{
	uint8_t buffer[3] = {0x00, 0x01, 0x02},buffersize=3;

	now = milis;
	timers_control_timer0_init();
	serial_com_USART_init();        //Call the USART initialization code

	// Initialize AVR for use with mirf
	mirf_init();
	// Wait for mirf to come up
	while(milis <= 50);
	// Activate interrupts
//	sei();
	// Configure mirf
	mirf_config();
	// Test communication



	while(1)
	{        //Infinite loop
		serial_com_echo_function();
#ifdef D_SERIAL
	serial_com_USART_send(0x03);
#endif
		mirf_send(buffer,buffersize);
#ifdef D_SERIAL
	serial_com_USART_send(0x04);
#endif
//		while (!mirf_data_ready());
//		mirf_get_data(buffer);

		if(mirf_data_ready())
		{
#ifdef D_SERIAL
	serial_com_USART_send(0x05);
#endif
			mirf_get_data(buffer);
		}

	 }

return 0;
}
